<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends CommonController {
    public function index(){
    	$cate = M('category');
    	$product = M('product as a');
    	$pro_inventory = M('pro_inventory');
    	$cate_list = $cate->where(['pid'=>0])->field('catename,cate_id')->select();//分类列表

    	$mid_left = $product->field('a.pro_name,b.price,a.pro_id')->join('rl_pro_inventory as b on b.pro_id = a.pro_id')->order('create_time desc')->find();


    	// field('a.pro_name,b.price')->join('rl_pro_inventory as b on b.pro_id = a.pro_id')->order('create_time desc')
    	$products = $product->field('pro_id,pro_name')->select();
    	$mid_right = array();
    	foreach($products as $val){
    		$price = $pro_inventory->field('price')->where(['pro_id'=>$val['pro_id']])->find();
    		$mid_right[] = array('price'=>$price['price'],'pro_name'=>$val['pro_name'],'pro_id' => $val['pro_id']);

    	}
    	$this->assign('mid_right',$mid_right);
    	$this->assign('mid_left',$mid_left);
    	$this->assign('cate_list',$cate_list);
      	$this -> display();
    }

    public function header(){
    	$this -> display('Home/Common');
    }

    // public function test(){
    //     $first = '1 2 3';

    //     $sec = str_split($first);
       
    //     dump($sec) ;
        
    // }
}